package harima.agameditor.mapeditor.control;

import java.io.File;

import harima.agameditor.common.control.AwesomeEditorEnviroment;
import harima.agameditor.common.ui.GenericTreeNode;
import harima.agamengine.loaders.IMapSerializer;

public class MapEditorServices {

	IMapSerializer mapSerializer;
	
	public GenericTreeNode getMapHierachy() {
		String mapsPath = AwesomeEditorEnviroment.getPath(AwesomeEditorEnviroment.MAPS_PATH);
		GenericTreeNode rootNode = new GenericTreeNode("Maps", mapsPath);
		
		addMapsToDirectory(mapsPath, rootNode);
		return rootNode;
	}

	public void addMapsToDirectory(String _path, GenericTreeNode node) {
		if(mapSerializer != null)
		{
			File[] files = mapSerializer.findMapsInDir(new File(_path));
			if(files != null)
			{
				for(File file : files)
				{
					node.add(new GenericTreeNode(file.getName(), file.getAbsolutePath()));
				}	
			}			
		}
	}

	public void setMapSerializer(IMapSerializer _serializer) {
		mapSerializer = _serializer;
	}

}
